﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AbstraX.Contracts;
using MvvmTreeView;
using System.Windows;
using System.Diagnostics;
#if SILVERLIGHT
using AbstraX.ClientInterfaces;
# else
using AbstraX.ServerInterfaces;
#endif
using AbstraX;
using EntityProvider.Web;
namespace EntityProvider.Web.Entities.Client
{
#if SILVERLIGHT
            
    public class EntityProviderExtension : IAbstraXExtension, IEntityProviderExtension
    {
        private IBase baseObject;
        private ITreeNode treeNode;
        private ContextMenu contextMenu;

        public void Initialize(IBase baseObject, ITreeNode treeNode)
        {
            this.baseObject = baseObject;
            this.treeNode = treeNode;
        }


    #region EntityContainer
        private void NewEntityContainer(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void RenameEntityContainer(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void DeleteEntityContainer(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }
    #endregion

    #region EntityType
        private void NewEntityType(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void RenameEntityType(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void DeleteEntityType(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void AddRelatedEntityType(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void RemoveRelatedEntityType(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }
    #endregion

    #region Property
        private void NewProperty(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void RenameProperty(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void DeleteProperty(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }
    #endregion

    #region NavigationProperty
        private void NewNavigationProperty(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void RenameNavigationProperty(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void DeleteNavigationProperty(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void SelectMultiplicity(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }
    #endregion

    #region Comments
        private void ViewComments(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void AddComments(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }

        private void EditComments(object sender, RoutedEventArgs r)
        {
            MessageBox.Show(baseObject.GetType().Name);
        }
    #endregion

        public ContextMenu ContextMenu
        {    
            get
            {
                if (contextMenu == null)
                {
                    switch (baseObject.GetType().Name)
                    {
                        case "Entity_Container":
        
                            contextMenu = new ContextMenu
                            {
                                Items = new List<IContextMenuItem>()
                                {
                                    new ContextMenuItem(null, "New EntityContainer", null, NewEntityContainer),
                                    new ContextMenuItem(null, "Rename EntityContainer", null, RenameEntityContainer),
                                    
                                    new ContextMenuItem(null, "View Comments", null, ViewComments),
                                    
                                    new ContextMenuItem(null, "Add Comments", null, AddComments),
                                    new ContextMenuItem(null, "Edit Comments", null, EditComments),

                                    new ContextMenuItem(null, "Delete EntityContainer", null, DeleteEntityContainer),
                                }
                            };
                            break;

                        case "Entity_Set":
                            contextMenu = null;
                            break;

                        case "EntityType":
        
                            contextMenu = new ContextMenu
                            {
                                Items = new List<IContextMenuItem>()
                                {
                                    new ContextMenuItem(null, "New EntityType", null, NewEntityType),
                                    new ContextMenuItem(null, "Rename EntityType", null, RenameEntityType),
                                    
                                    new ContextMenuItem(null, "View Comments", null, ViewComments),
                                    
                                    new ContextMenuItem(null, "Add Comments", null, AddComments),
                                    new ContextMenuItem(null, "Edit Comments", null, EditComments),

                                    new ContextMenuItem(null, "Delete Entity Type", null, DeleteEntityType),

                                    new ContextMenuItem(null, "Add Related EntityType", null, AddRelatedEntityType),
                                    new ContextMenuItem(null, "Remove Related EntityType", null, RemoveRelatedEntityType),
                                }
                            };
                            break;

                        case "EntityProperty":
                            contextMenu = new ContextMenu
                            {
                                Items = new List<IContextMenuItem>()
                                {
                                    new ContextMenuItem(null, "New Property", null, NewProperty),
                                    new ContextMenuItem(null, "Rename Property", null, RenameProperty),
                                    
                                    new ContextMenuItem(null, "View Comments", null, ViewComments),
                                    
                                    new ContextMenuItem(null, "Add Comments", null, AddComments),
                                    new ContextMenuItem(null, "Edit Comments", null, EditComments),

                                    new ContextMenuItem(null, "Delete Property", null, DeleteProperty),
                                }
                            };
                            break;

                        case "NavigationProperty":
                            contextMenu = new ContextMenu
                            {
                                Items = new List<IContextMenuItem>()
                                {
                                    new ContextMenuItem(null, "New NavigationProperty", null, NewNavigationProperty),
                                    new ContextMenuItem(null, "Rename NavigationProperty", null, RenameNavigationProperty),
                                    
                                    new ContextMenuItem(null, "View Comments", null, ViewComments),
                                    
                                    new ContextMenuItem(null, "Add Comments", null, AddComments),
                                    new ContextMenuItem(null, "Edit Comments", null, EditComments),

                                    new ContextMenuItem(null, "Delete NavigationProperty", null, DeleteNavigationProperty),

                                    new ContextMenuItem(null, "SelectMultiplicity", null, SelectMultiplicity),
                                }
                            };
                            break;

                        default:
                            contextMenu = null;
                            break;
                    }
                }
            return contextMenu;
            }
        }
    }
#endif
}
